package demo.orm.pojo;

import base.model.Result;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import demo.orm.JDBCUtils;

import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * @author : GuoFei
 * @date : 2019/1/25 17:31
 */
public class ORMBaseDao<T> {

    private static final JDBCUtils jdbcUtils = new JDBCUtils();

    private Class<T> t;

    @SuppressWarnings("unchecked")
    private Class<T> getTClass() {
        if (t == null) {
            t = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
        }
        return t;
    }

    public List<T> list(String sql){
        return jdbcUtils.queryList(sql,getTClass());
    }


    public static void main(String[] args) {
        System.out.println("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".length());
        System.out.println("begin");
        System.out.println("out-begin");
        try {
            System.exit(0);
        }finally {
            System.out.println("finally");
        }
        System.out.println("out-end");
        System.out.println("end");
        LinkedList<Result> test = new LinkedList<>();
        test.add(Result.successForMessage("number 1"));
        test.add(Result.successForMessage("number 2"));
        test.add(Result.successForMessage("number 3"));
        test.add(Result.successForMessage("number 4"));
        test.add(Result.successForMessage("number 5"));
        test.add(Result.successForMessage("number 6"));
        test.add(Result.successForMessage("number 7"));
        test.add(Result.successForMessage("number 8"));
        test.add(Result.successForMessage("number 9"));
        test.add(Result.successForMessage("number 10"));
        System.out.println("get(1)："+JSON.toJSONString(test.get(1)));
        System.out.println("poll()："+JSON.toJSONString(test.poll()));
        System.out.println("get(1)："+JSON.toJSONString(test.get(1)));
        System.out.println("getFirst()："+JSON.toJSONString(test.getFirst()));
        System.out.println("get(1)："+JSON.toJSONString(test.get(1)));
        System.out.println("getLast()："+JSON.toJSONString(test.getLast()));
        System.out.println("get(1)："+JSON.toJSONString(test.get(1)));
        System.out.println("peek()："+JSON.toJSONString(test.peek()));
        System.out.println("get(1)："+JSON.toJSONString(test.get(1)));





    }

}
